<?php


namespace App\Models;

use Eloquent;

/**
 * Class Group
 *
 * @package App\Models
 * @mixin Eloquent
 */
class Group extends Base
{
    // 数据表名
    protected $table = 'groups';

    // 数据主键
    protected $primaryKey = 'group_id';

    // 隐藏字段
    protected $hidden = ['updated_at'];

    // 批量赋值
    protected $fillable = [];

    // 自动维护时间字段
    public $timestamps = true;

    /**
     * 菜单数据（多对多关系）
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     */
    public function menus() {
        return $this->belongsToMany('App\Models\Menu', 'bind_group_menu', 'group_id', 'menu_id')
            ->select(['bind_group_menu.menu_id','menu_name','pid','uri','icon','menus.sort','is_hide'])
            ->orderBy('sort', 'asc')->orderBy('menu_id', 'asc');
    }
}
